package com.rowline.admin.module.util.utils;

import org.springframework.core.annotation.AnnotationUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * 根据对象和注解  获取注解信息的工具类
 * @author 198777
 * @date 2016-04-18
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public final class AnnotationUtil {
    /**
     * 获取注解信息
     * @param method
     * @param annotationType
     * @return
     */
	public static <A extends Annotation> A findAnnotation(Method method,
			Class<A> annotationType) {
		return AnnotationUtils.findAnnotation(method, annotationType);
	}
    /**
     * 获取注解对应的参数值
     * @param obj
     * @param annotationType
     * @return
     */
	public static Object getObjFieldValueByAnnotation(Object obj,
			Class annotationType) {
		try {
			//加载类
			Class cls = obj.getClass();
			while (cls != null) {
				//获取所有属性
				Field[] fields = cls.getDeclaredFields();
				for (Field field : fields) {
					//获取拥有annotationType这个注解的属性
					if (field.isAnnotationPresent(annotationType)) {
						//return PropertyUtils.getProperty(obj, field.getName());
					}
				}
				cls = cls.getSuperclass();
			}
		} catch (Exception ex) {
			return null;
		}
		return null;
	}

	private AnnotationUtil() {
	}

}
